<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8"/>
  <title>密码显示切换</title>
  <style>
    [v-cloak] {
      display: none;
    }
    body {
      padding: 40px 100px;
    }

    .search-box {
      margin-bottom:  30px;
    }
    .search-box:after {
      content: '';
      display: block;
      clear: both;
    }
    .search-box input {
      float: left;
      margin-left: -1px;
      padding: 0 10px;
      width: 200px;
      height: 30px;
      border: 1px solid #ccc;
      box-sizing: border-box;
      outline: medium;
    }
    .search-box .btn {
      float: left;
      margin-left: -1px;
      width: 80px;
      height: 30px;
      border: 1px solid #ccc;
      cursor: pointer;
      box-sizing: border-box;
      text-align: center;
      line-height: 28px;
      text-decoration: none;
      color: #333;
    }
    .search-box .btn:hover {
      color: #fff;
      background: #01A3D9;
    }

  </style>
</head>
<body>

  <div id="app" v-cloak>
    <div class="search-box">
      <input v-model="word" :type="type"/>
      <button class="btn" @click="changeType()">
        {{type == 'password' ? '显示密码' : '隐藏密码'}}
      </button>
    </div>
  </div>
  
  <script src="../lib/vue.3.4.js"></script>
  <script>
    const app = Vue.createApp({
      data () {
        return {
          type: 'password',
          password: '',
        }
      },
      methods: {
        changeType () {
          this.type = this.type == 'password' ? 'text' : 'password';
        }
      }
    }).mount('#app');
  </script>
</body> 
</html>